<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>小黑记事本</title>
  </head>
  <body>
    <h1>小黑记事本</h1>
    <div id="app">
      <div class="content">
        文本
        <input type="text" v-model="content" @keyup.enter="add()" />
        <button @click="add()">添加任务</button>
      </div>

      <ul>
        <li v-for="(item,index) in foot" :key="index">
          {{index + 1}}. {{item}} <button @click="del(index)">删除</button>
        </li>
      </ul>
     <div v-show="foot.length>0"> 合计：{{foot.length}} &nbsp;&nbsp; <button @click="clear()">清空</button></div>
    </div>

    <script src="/js/vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          content: "",
          foot: [],
        },
        methods: {
          add() {
            if (this.content.trim() === "") {
              alert("输入内容不能为空");
            } else {
              this.foot.push(this.content);
              this.content = "";
            }
          },
          del(id) {
            this.foot = this.foot.filter((item, index) => index !== id);
          },
          clear() {
            this.foot = [];
          },
        },
      });
    </script>
  </body>
</html>
